var orderBtn = document.getElementById('orderBtn');

orderBtn.addEventListener('click', function() {
  var inputs = document.querySelectorAll('.grade-table tbody input');
  var isMissing = false;

  // 检查是否有输入框未填写
  inputs.forEach(function(input) {
    if (input.value.trim() === '') {
      isMissing = true;
      return;
    }
  });

  if (isMissing) {
    alert("您还有信息未填写！");
  } else {
        var confirmed = confirm("确定录入吗？");
        if (confirmed) {
            // 构建要发送的数据对象
            var data = {};
            inputs.forEach(function(input, index) {
              data['input' + index] = input.value;
            });
            console.log(data);
            // 发送 AJAX 请求
            $.ajax({
              url: '/management/managerservlet/addNewTeacher',         // 添加新教师接口
              method: 'POST',
              data: data,
              success: function(response) {
                // 处理响应数据
                if (response.flag) {
                  // 登录成功
                  console.log(response.errorMsg);
                  alert("录入成功！");
                  window.location.href = "mnglogin_teacher.html";
                } else {
                  // 登录失败
                }
              },
              error: function(xhr, status, error) {
                // 处理错误
                console.log(error);
              }
            });
        }
  }
});


var content = document.querySelector('.content');
content.addEventListener('mouseenter', function() {
  content.style.transition = 'background-color 0.3s';
  content.style.backgroundColor = 'rgba(230,230,230,0.6)'; // 将透明度更改为 0.5，使背景色加深
});

content.addEventListener('mouseleave', function() {
  content.style.transition = 'background-color 0.3s';
  content.style.backgroundColor = 'rgba(230,230,230,0.2)'; // 将透明度恢复为 0.2，使背景色变浅
});

var container = document.querySelector('.container');

/* 监听鼠标进入.container元素事件 */
container.addEventListener('mouseleave', function() {
  container.style.transition = 'opacity 0.3s';
  container.style.opacity = '0.2';
});

container.addEventListener('mouseenter', function() {
  container.style.transition = 'opacity 0.3s';
  container.style.opacity = '1';
});

$(document).keydown(function(event) {
  if (event.keyCode == 13) { // 13代表回车键的键码
    $('#orderBtn').click();
  }
});

    // 延迟隐藏遮罩层
    window.addEventListener('load', function() {
        setTimeout(function() {
            var overlay = document.querySelector('.overlay');
            var overlay2 = document.querySelector('.overlay2');
            var container = document.querySelector('.container');
            overlay.style.height = '0%';
            overlay.style.opacity = '0';
            overlay2.style.height = '0%';
            overlay2.style.opacity = '0';
        }, 10); // 延迟2秒隐藏遮罩层
    });